#include "fhtest.h"


#define LABELWIDTH 100
#define LABELHIGHTH 30
#define AVGHEIGHT 30

FhTest::FhTest(QWidget *parent) :
    QWidget(parent)
{
    QFont ft;
    ft.setPixelSize(20);

    QLabel *titleLabel = new QLabel(tr("阻抗测试"));
    titleLabel->setFont(ft);
    ft.setPixelSize(15);
    QLabel *dianliu1 = new QLabel(tr("输入一次电流:"));
    dianliu1->setFont(ft);
    QLabel *dianliu2 = new QLabel(tr("输入二次电流:"));
    dianliu2->setFont(ft);
    QLabel *cedian = new QLabel(tr(" 请输入测试点:"));
    cedian->setFont(ft);

    QLabel *dianwei1 = new QLabel(tr("A"));
    dianwei1->setFont(ft);
    QLabel *dianwei2 = new QLabel(tr("A"));
    dianwei2->setFont(ft);
    QLabel *dianwei3 = new QLabel(tr("%"));
    dianwei3->setFont(ft);
    QPushButton *okBtn = new QPushButton(tr("测试开始"));
    okBtn->setFont(ft);

    currentEdit1=new QLineEdit;
    currentEdit1->setFixedSize(150,LABELHIGHTH-5);
    currentEdit1->setFont(ft);
    currentEdit1->setStyleSheet("QLineEdit{border-width:0;border-style:outset}");
    currentEdit1->installEventFilter(this);
    currentEdit2=new QLineEdit;
    currentEdit2->setFixedSize(150,LABELHIGHTH-5);
    currentEdit2->setFont(ft);
    currentEdit2->setStyleSheet("QLineEdit{border-width:0;border-style:outset}");
    currentEdit2->installEventFilter(this);
    testEdit=new QLineEdit;
    testEdit->setFixedSize(150,LABELHIGHTH-5);
    testEdit->setFont(ft);
    testEdit->setStyleSheet("QLineEdit{border-width:0;border-style:outset}");
    testEdit->installEventFilter(this);
    QHBoxLayout *zktest = new QHBoxLayout;
    zktest->addStretch(1);
    zktest->addWidget(titleLabel);
    zktest->addStretch(1);

    QHBoxLayout *zktest1 = new QHBoxLayout;
    zktest1->addStretch(1);
    zktest1->addWidget(dianliu1);
    zktest1->addWidget(currentEdit1);
    zktest1->addWidget(dianwei1);
    zktest1->addStretch(1);

    QHBoxLayout *zktest2 = new QHBoxLayout;
    zktest2->addStretch(1);
    zktest2->addWidget(dianliu2);
    zktest2->addWidget(currentEdit2);
    zktest2->addWidget(dianwei2);
    zktest2->addStretch(1);
    QHBoxLayout *zktest3 = new QHBoxLayout;
    zktest3->addStretch(1);
    zktest3->addWidget(cedian);
    zktest3->addWidget(testEdit);
    zktest3->addWidget(dianwei3);
    zktest3->addStretch(1);

    QHBoxLayout *zktest4 = new QHBoxLayout;
    zktest4->addStretch(1);
    zktest4->addWidget(okBtn);
    zktest4->addStretch(1);

    QVBoxLayout *main = new QVBoxLayout;
    main->addSpacing(20);
    main->addLayout(zktest);
    main->addSpacing(10);
    main->addLayout(zktest1);
    main->addSpacing(10);
    main->addLayout(zktest2);
    main->addSpacing(10);
    main->addLayout(zktest3);
    main->addSpacing(10);
    main->addLayout(zktest4);
    main->addStretch(1);

    setLayout(main);
    theKeyBoard = new Dialog(this);

}

bool FhTest::eventFilter(QObject *obj, QEvent *event)
{
    if( obj == currentEdit1)
    {
        if(event->type() == QEvent::FocusIn)
        {
            theKeyBoard->setCurrentActive(currentEdit1);
        }
        else if(event->type() == QEvent::FocusOut)
        {
            theKeyBoard->hide();
        }
    }
    if( obj == currentEdit2)
    {
        if(event->type() == QEvent::FocusIn)
        {
            theKeyBoard->setCurrentActive(currentEdit2);
        }
        else if(event->type() == QEvent::FocusOut)
        {
            theKeyBoard->hide();
        }
    }
    if( obj == testEdit)
    {
        if(event->type() == QEvent::FocusIn)
        {
            theKeyBoard->setCurrentActive(testEdit);
        }
        else if(event->type() == QEvent::FocusOut)
        {
            theKeyBoard->hide();
        }
    }
    return false;
}
void FhTest::recvResult(QByteArray rcvdByte)
{

}
